from xdg.Exceptions import ValidationError
from django.core.validators import EMPTY_VALUES, RegexValidator, URLValidator, EmailValidator, MaxLengthValidator, email_re, MinLengthValidator
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext, ugettext_lazy as _
import transsys

class UniqueSimGenexProgramValidator(object):
    message = _(u'Name of transsys programs must be unique!')
    sgxs = None
    def __init__(self, sgxs, message=None):
        self.sgxs = sgxs
        if message:
            self.message = message

    def __call__(self, value):
        for sgx in self.sgxs:
            if value == sgx["name"]:
                raise ValidationError(self.message)

class UniqueProcedureValidator(object):
    message = _(u'Name of procedure must be unique!')
    sgx = None
    def __init__(self, sgx, message=None):
        self.sgx = sgx
        if message:
            self.message = message

    def __call__(self, value):
        for procedure in self.sgx.procedure_defs:
            if value == procedure.procedure_name:
                raise ValidationError(self.message)
